public class MySort {
    public static void countSort(int[] array){
        int minVal = array[0] ;
        int maxVal = array[0];
        //求最大和最小
        for (int i = 1; i < array.length; i++) {
            if(array[i] > maxVal){
                maxVal = array[i] ;
            }
            if(array[i] < minVal){
                minVal = array[i] ;
            }
        }
         int[] count = new int[maxVal - minVal + 1] ;
        for (int i = 0; i < array.length; i++) {
              int val = array[i] ;
              count[val-minVal] ++ ;
        }

        //遍历计数数组，把数据写会array
        int index = 0 ;
        for (int i = 0; i < count.length; i++) {
            while (count[i] > 0){
                array[index] = i + minVal ;
                count[i] -- ;
                index ++ ;
            }
        }

    }
}
